// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
#pragma once
#include "LatLon.h"
#include "ILocationService.h"
#include "WebException.h"

namespace Weathr
{
    // Dataflow agent that assists with lookups from an ILocationService object.
    class LocatorAgent : public concurrency::agent
    {
    public:
        explicit LocatorAgent(std::shared_ptr<Web::ILocationService> locationService);

        void QueueLocationRequest(float latitude, float longitude);

        concurrency::unbounded_buffer<std::shared_ptr<Web::Location>>* GetOutputBuffer()
        {
            return &m_outputBuffer;
        }

        concurrency::unbounded_buffer<Web::WebException>* GetErrorBuffer()
        {
            return &m_errorBuffer;
        }

        std::shared_ptr<Web::ILocationService> GetLocationService() const
        {
            return m_locationService;
        }

    protected:
        virtual void run();

    private:
        std::shared_ptr<Web::ILocationService> m_locationService;
        concurrency::overwrite_buffer<std::tuple<float, float>> m_requestBuffer;
        std::unique_ptr<concurrency::call<std::tuple<float, float>>> m_processBuffer;
        concurrency::unbounded_buffer<std::shared_ptr<Web::Location>> m_outputBuffer;
        concurrency::unbounded_buffer<Web::WebException> m_errorBuffer;
    };
}